<template>
  <div class="category-list">
    <div
      class="category-list-item"
      v-for="(item, index) in categoryList"
      :key="item.maitKey"
      :class="{ active: currentIndex === index }"
      @click="itemClick(index, item.maitKey)"
    >
      {{ item.title }}
    </div>
  </div>
</template>

<script>
export default {
  name: "CategoryList",
  props: {
    categoryList: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      currentIndex: 0,
    };
  },
  methods: {
    itemClick(index, maitKey) {
      this.currentIndex = index;
      this.$emit("categoryListItemClick", maitKey);
    },
  },
};
</script>

<style scoped>
.category-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  background-color: #f3f1f1;
}
.category-list-item {
  height: 50px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.active {
  border-left: 7px solid var(--color-tint);
  font-size: 15px;
  font-weight: 600;
  color: var(--color-tint);
}
</style>
